﻿using Sidvall.Serialization;

namespace Sidvall.Net
{
    public class ProxySettings
    {
        #region Public Members

        public string Address { get; set; }
        public CredentialsSettings Credentials { get; set; }
        public bool? PreAuthenticate { get; set; }
        public bool? UseDefaultCredentials { get; set; }

        #region Copy

        public ProxySettings Copy()
        {
            var item = new ProxySettings()
            {
                Address = this.Address,
                PreAuthenticate = this.PreAuthenticate,
                UseDefaultCredentials = this.UseDefaultCredentials,
            };
            if (this.Credentials != null)
                item.Credentials = this.Credentials.Copy();
            return item;
        }

        #endregion
        #region IsEqual

        public bool IsEqual(ProxySettings obj)
        {
            return IsEqual(this, obj);
        }

        #endregion
        #region IsEqual - Static

        public static bool IsEqual(ProxySettings item1, ProxySettings item2)
        {
            if (item1 == null)
            {
                if (item2 == null)
                    return true;
                else
                    return false;
            }
            else if (item2 == null)
                return false;
            if (!item1.Address.Equals(item2.Address, true, System.StringComparison.OrdinalIgnoreCase))
                return false;
            if (item1.PreAuthenticate != item2.PreAuthenticate)
                return false;
            if (item1.UseDefaultCredentials != item2.UseDefaultCredentials)
                return false;
            if (!CredentialsSettings.IsEqual(item1.Credentials, item2.Credentials))
                return false;
            return true;
        }

        #endregion

        #endregion
        #region Constructors

        public ProxySettings()
        {
        }

        #endregion
    }
}
